package com.example.module_main

import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.lib_common.base.BaseActivity
import com.example.lib_common.base.BaseViewModel
import com.example.module_main.databinding.ActivityMainBinding
import com.example.module_main.ui.adapter.CustomTabEntityy
import com.example.module_main.ui.adapter.FragmentAdepter
import com.example.module_message.ui.MessageFragment
import com.example.module_mine.ui.MineFragment
import com.example.module_notice.ui.NoticeFragment
import com.example.module_park.ui.ParkFragment
import com.example.module_service.ui.ServiceFragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/main/MainActivity")
@AndroidEntryPoint
class MainActivity :BaseActivity<BaseViewModel,ActivityMainBinding>() {

    private lateinit var adepter: FragmentAdepter
    private val list = mutableListOf<Fragment>()


    override val mLayoutResId: Int
        get() = R.layout.activity_main



    override fun initView() {

        //将碎片加入集合
        list.add(ParkFragment())
        list.add(ServiceFragment())
        list.add(MessageFragment())
        list.add(NoticeFragment())
        list.add(MineFragment())
        //实例化碎片适配器
        adepter = FragmentAdepter(this@MainActivity,list);
        mBinding.vp?.setAdapter(adepter);

        mBinding.tl.textsize= 10F
        val arrayList = ArrayList<CustomTabEntity>();
        arrayList.add( CustomTabEntityy("首页", R.drawable.tab_home_lan, R.drawable.tab_home_hui));
        arrayList.add( CustomTabEntityy("服务", R.drawable.tab_service_lan, R.drawable.tab_service_hui))
        arrayList.add( CustomTabEntityy("消息", R.drawable.tab_message_lan, R.drawable.tab_message_hui))
        arrayList.add( CustomTabEntityy("公告", R.drawable.tab_notice_lan, R.drawable.tab_notice_hui))
        arrayList.add( CustomTabEntityy("我的", R.drawable.tab_mine_lan, R.drawable.tab_mine_hui))
        //为什么要用ArrayList集合，因为我们可以点进去看他的原码，需要的类型是ArrayList
        mBinding.tl?.setTabData(arrayList);
        //导航绑定视图滑动切换工具
        mBinding.tl?.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                mBinding.vp?.setCurrentItem(position);
            }

            override fun onTabReselect(position: Int) {

            }

        })
        //视图滑动切换工具绑定导航
        mBinding.vp?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                mBinding.tl?.setCurrentTab(position)
            }

        })

    }
    override fun initData() {
    }


    override fun initListener() {

    }


}